/**
 * 用户持久模块
 */
define('store/UserStore', ['WxCore','restTemplate'], function (wxCore,restTemplate) {

    const module= {
        storeName: 'UserStore',
        namespaced: true,
        state: {},
        mutations: {},
        actions: {
            getValidateRule() {
                return {
                    account: [
                        {required: true, message: '登录账号不能为空', trigger: 'blur'}
                    ],
                    userPass: [
                        {required: true, message: '登录密码不能为空', trigger: 'blur'}
                    ],
                    userName: [
                        {required: true, message: '用户姓名不能为空', trigger: 'blur'}
                    ],
                    email: [
                        {required: true, message: '邮箱不能为空', trigger: 'blur'},
                        {type: 'email', message: '邮箱格式不正确', trigger: 'blur'}
                    ]
                }
            },
            list({state, commit}, {pageIndex, pageSize}) {
                return restTemplate.request({
                    url: '/api/OauthUser/list',
                    params: {
                        pageIndex,
                        pageSize
                    },
                    method: 'get'
                })
            },
            find({state, commit}, userId) {
                return restTemplate.request({
                    url: '/api/OauthUser/find',
                    params: {
                        id: userId
                    },
                    method: 'get'
                })
            },
            save({state, commit}, vo) {
                const requestUrl = (vo.userId && vo.userId !== '') ? '/api/OauthUser/update' : '/api/OauthUser/add'
                return restTemplate.request({
                    url: requestUrl,
                    method: 'post',
                    data: vo
                })
            },
            delete({state, commit}, userId) {
                return restTemplate.request({
                    url: 'api/OauthUser/delete',
                    method: 'post',
                    params: {id: userId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            }
        }
    };
    return module;
})